package com.sacodemel.financeiro.persistencia.dao.factory;

import com.sacodemel.financeiro.util.ResourceService;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;



public class ConnectionUtil {

	protected static Connection getConexao() {
		Connection con = null;

		try {

			Class.forName(ResourceService.getInstance(ResourceService.CONFIG).getProperty("jdbc.oracle.driver"));

			String url = ResourceService.getInstance(ResourceService.CONFIG).getProperty("jdbc.oracle.url");
			
			
			con = DriverManager
					.getConnection(url, ResourceService.getInstance(
							ResourceService.CONFIG).getProperty("jdbc.user"),
							ResourceService.getInstance(ResourceService.CONFIG)
									.getProperty("jdbc.password"));

			 
			
		} catch (Exception e) {
			System.out.println("ERRO ==> " + e.getMessage());
			e.printStackTrace();
			// TODO: handle exception
		}

		return con;
	}

	protected void fechar(ResultSet aResultSet, Statement aStatement,
			Connection aConnection) {
		try {
			if (aResultSet != null) {
				aResultSet.close();
			}
			if (aStatement != null) {
				aStatement.close();
			}
			if (aConnection != null) {
				aConnection.close();
			}
		} catch (SQLException e) {
			System.out.println("ERRO: " + e.getMessage());
			e.printStackTrace();
			// TODO: handle exception
		}
	}

}

